package com.zhanghaijun.createCode.service;

import com.zhanghaijun.createCode.util.Constant;
import com.zhanghaijun.createCode.util.PrintUtil;
import freemarker.core.Environment;
import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by zhanghaijun on 15/4/29.
 */
public class TestService {
    /**
     * freemarker API 基本用法
     * @throws Exception
     */
     public static void CreateTestFile()throws Exception{
         Configuration cfg = new Configuration();
         cfg.setClassForTemplateLoading(TestService.class, "/");
         Template t = cfg.getTemplate("test.ftl");
         Map root = new HashMap();
         root.put("hello", "hello_world");
         String filePath = Constant.outPutRootPath+"hello.txt";
         PrintUtil.println("file create path is:" + filePath);
         File file = new File(filePath);
         file.createNewFile();
         FileWriter fileWriter = new FileWriter(file);
         Environment ev = t.createProcessingEnvironment(root, fileWriter, null);
         ev.process();
     }

}
